﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace WindowsGame1
{
    public class Lazor
    {
        public Vector2 origin;
        public float top = 0;
        public float bottom = 0;
        public float width = 128;
        public bool alive = false;
        public float speed = 4000;
        public Color color0 = Palette.planeWeaponColor0;
        public Color color1 = Palette.planeWeaponColor2;
        public float colorTime = 0;

        public bool Update(Timer t)
        {
            colorTime += t.Delta;

            top -= speed * t.Delta;
            if (alive == false)
                bottom -= speed * t.Delta;

            return bottom > 0;
        }

        public Rectangle ComputeRect()
        {
            int x = (int)(origin.X - width * 0.5f);
            int y = (int)top;
            int w = (int)width;
            int h = (int)(bottom - top);
            return new Rectangle(x, y, w, h);
        }

        public void Draw(SpriteBatch sb)
        {
            // sb.Draw(texture, pos + off, null, new Color(255, 128, 0, 255), rotation, origin, scale, SpriteEffects.None, 1.0f);            
            float x = origin.X - width * 0.5f;
            float y = top;
            float sx = width;
            float sy = bottom - top;
            float border = 8;

            {
                float s = (float)Math.Sin(colorTime * 10.0f) * 0.5f + 0.5f;
                Color color = Color.Lerp(color0, color1, s);
                sb.Draw(Game1.whiteTexture, new Vector2(x, y), null, color, 0, Vector2.Zero, new Vector2(sx, sy), SpriteEffects.None, 1.0f);
            }

            {
                float s = (float)Math.Sin(1 + colorTime * 10.0f) * 0.5f + 0.5f;
                Color color = Color.Lerp(color0, color1, s);
                sb.Draw(Game1.whiteTexture, new Vector2(x + border, y), null, color, 0, Vector2.Zero, new Vector2(sx - border * 2.0f, sy), SpriteEffects.None, 1.0f);
            }
        }
    }
}
